import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    //submit是用来传递评测信息的对象
    submit: {
      evaluation: {},
      source: {},
      student: {},
      result: [],
    },
  },
  mutations: {
    clearContain(state){
      state.submit.evaluation={};
      state.submit.source={};
      state.submit.student={};
      state.submit.result=[];
    },
    //在/evalist页面获取评测信息
    getEvaluation(state, info) {
      let { createdTime, endTime, id, name, published, startTime } = info;
      state.submit.evaluation = {
        createdTime,
        endTime,
        id,
        name,
        published,
        startTime,
      };
    },
    //在/evalist页面获取选中科目的信息
    getSource(state, info) {
      //localStorage方法解决由/detail跳转/general页面传值的问题
      localStorage.setItem("subInfo", JSON.stringify(info));
      let { alias, classHours, credit, evaluated, id, title } = info;
      state.submit.source = {
        alias,
        classHours,
        credit,
        evaluated,
        id,
        title,
      };
    },
    //在/login页面获取学生信息
    getStudentInfo(state, info) {
      state.submit.student = info;
    },
    //在/general页面获取教师信息
    getTeacherInfo(state, info) {
      state.submit.result = info;
    },
  },
  actions: {},
  modules: {},
});
